home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1964 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: newshost.lanl.gov!usenet
  2. From: luke@raj2.tn.cornell.edu (Luke Emmert)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: manipulating the stack in C
  5. Date: 25 Jan 1996 16:27:44 GMT
  6. Organization: Los Alamos National Laboratory
  7. Sender: -Not-Authenticated-[6486]
  8. Message-ID: <4e8b20$lsq@newshost.lanl.gov>
  9. NNTP-Posting-Host: scan-o-matic.mst.lanl.gov
  10. X-Posted-From: InterNews 1.0.8@scan-o-matic.mst.lanl.gov
  11. Xdisclaimer: No attempt was made to authenticate the sender's name.
  12.  
  13.   I'm currently writing an assembly function that takes a variable
  14. number of arguments.  The last of the arguments is indicated by forcing
  15. the stack to point at itself(a low probability occurence so I hope). 
  16. The function is called from C code and I therefore need to get C to do
  17. something weird with the stack.  Unfortunately, I need to make
  18. assumptions about how the compiler will produce binary.
  19.  
  20.   The code looks like the following:
  21.  
  22. #define LAST_ARG (get_stack())
  23.  
  24.   foo( arg1, arg2, arg3, arg4, LAST_ARG );
  25.  
  26. where get_stack() simply returns the current
  27. stack value:
  28.  
  29. _get_stack:
  30.       move.l   a7,d0
  31.       rts
  32.  
  33.   The problem arose last night, when I removed a printf() statement
  34. that I used for debugging.  After disassembling the binary I found that
  35. the stack was loaded in different ways in each case.  My program
  36. assumes a particular way of loading the stack and that's why it failed.
  37.  
  38.   What I'd like to do is have something in-line that loads the current
  39. stack value rather like
  40.   move.l a7,(a7)
  41. without having to use a function call.  I'm currently using SAS C v5.10
  42. and I'm pretty sure that this cannot be done, but if any one has a
  43. suggestion I would appreciate it.
  44.  
  45. thank you,
  46. -luke
  47.  
  48. * Luke Emmert   'luke@raj2.tn.cornell.edu'
  49.